package LeetCode;

public class LC_326_PowerofThree {

    public static void main(String[] args) {

    }

    static class Solution {
        public boolean isPowerOfThree(int n) {
            if (n == 1) return true;
            while (n > 0) {
                int m = n % 3;
                if (m == 0) {
                    n = n / 3;
                    if (n == 1)
                        return true;
                } else {
                    return false;
                }
            }
            return false;
        }

    }

    static class Solution_1 {
        boolean isPowerOfThree(int n) {
            return n != 0 && (n == 1 || n > 1 && n % 3 == 0 && isPowerOfThree(n / 3));
        }
    }
}